<?php

 defined('IN_PHPCMS') or exit('No permission resources.');

 define('API_URL_GET_KEYWORDS', 'http://tool.phpcms.cn/api/get_keywords.php');
 function get_keywords($data, $number = 3) {
     $data = trim(strip_tags($data));
     if(empty($data)) return '';
     $http = pc_base::load_sys_class('http');
     if(CHARSET != 'utf-8') $data = iconv('utf-8', CHARSET, $data);
     else $data = iconv('utf-8', 'gbk', $data);
     $http->post(API_URL_GET_KEYWORDS, array('siteurl'=>SITE_URL, 'charset'=>CHARSET, 'data'=>$data, 'number'=>$number));
     if($http->is_ok()) {
         if(CHARSET != 'utf-8') return $http->get_data();
         else return iconv('gbk', 'utf-8', $http->get_data());
     }
     return '';  
 }

   // print_r($_POST);
 if(!$_POST['siteid']) exit("站点ID不存在");
 $categorys = getcache('category_content_'.$_POST['siteid'],'commons');
//echo $categorys;
   if($_POST){  
     $info['catid'] = isset($_POST['catid']) ? intval($_POST['catid']): exit("板块ID不存在");
     $info['title'] = isset($_POST['title']) ? trim($_POST['title']) : exit('标题不能为空');
     $info['laiyuan'] = isset($_POST['source']) ? trim($_POST['source']) : exit('来源不能为空');
     $info['content'] = isset($_POST['content']) ? trim($_POST['content']) : exit('内容不能为空');
     $url=isset($_POST['article_url']) ? trim($_POST['article_url']) : exit('url不能为空');
     $picture=explode(",",$_POST['picture']);
     // $pic=isset($picture[0]) ? trim($picture[0]) : exit('图片地址不能为空');

     if ($picture[0]==null) {
        $info['thumb']="";
     }
     else
     {  
        $info['thumb']=$url.$picture[0];
     }
     

     // $info['articles_id'] = isset($_POST['article_id']) ? intval($_POST['article_id']): exit("文章id不能为空！");
     $db = pc_base::load_model('content_model');
     $category = $categorys[$_POST['catid']];
     $modelid = $category['modelid'];
     $db->set_model($modelid);
     
     //如果该栏目设置了工作流，那么必须走工作流设定
    // $setting = string2array($category['setting']);
    // $workflowid = $setting['workflowid'];
    $info['status'] = 99;
    $info['keywords'] = !empty($_POST['keywords']) ? $_POST['keywords'] : get_keywords($info['title'], 3);
    $info['description'] = !empty($_POST['description']) ? $_POST['description'] :mb_substr(str_replace(array("\r","\n","\t","[page]","[/page]","&ldquo;","&rdquo;","&nbsp;","&emsp;","&emsp;&emsp;&emsp;&emsp;","&emsp;&emsp;"," ","　 ","  "),"",strip_tags($info['content'])),0,130,'UTF8');
     $info['username'] = isset($_POST['username']) ? trim($_POST['username']) : '';
     $time=strtotime($_POST['pushtime']);
     $info['inputtime'] = isset($time) ? trim($time) : ''; 
     //$db->add_content($info); 
      $array=array($_POST['article_id']);
      
       
      if($db->add_content($info)){
         $win='Yes';
         foreach ($array as $key => $value) {
           
        }
         exit($value.",".$win); 
      }
      else{
         $failure='No';
         foreach ($array as $key => $value) {
         
        }
         exit($value.",".$failure); 
      }
 }else{
     $str = '';
     foreach($categorys as $k=>$v){
         if(!$v['type']) $str .=  $v['catid'].'-'.$v['catname'].'|';
     }
     exit($str);
 }
?>
